class Solution(object):
    def mirrorReflection(self, p, q):
        """
        :type p: int
        :type q: int
        :rtype: int
        """
        if 0 == q:
            return 0
        x, y = 0, 0
        while 1:
            x += p
            y += q
            if 0 == y % p:
                break
        # print x, y, x / p, y / p
        if (x / p) % 2:
            if (y / p) % 2:
                return 1
            return 0
        return 2
        
def main():
    sol = Solution()
    print(sol.mirrorReflection(3,2))
    
if __name__=="__main__":
    main()